<?php namespace Admin\Controller;
use Hdphp\Controller\Controller;
//后台登录控制器
class LoginController extends Controller{
	private $model;
	public function __init(){
		//实例化User模型
		$this->model = new \Common\Model\Admin;
	}
	public function index(){
		if(IS_POST){
		   // p(Q("post."));
			//接收数据
			$account = Q('account');
			$password = Q('password','','md5');
			//判断用户名是否存在
			$data = $this->model->where("account='{$account}'")->find();
			//p($data);exit;
			if(!$data) View::error('用户名输入错误');
			//判断密码是否正确
			if($data['password'] != $password) View::error('密码输入错误');
			//登录成功
			$_SESSION['admin_id'] = $data['admin_id'];
			$_SESSION['account']  = $data['account'];
			//登录时间 登录IO
			$this->model->where("admin_id={$_SESSION['admin_id']}")->save(array(
			'login_time'=>time(),
			'login_ip'  =>$_SERVER["REMOTE_ADDR"]
			));
			View::success('登录成功','Index/index');
		}
		View::make();
	}
	//退出
	public function logout(){
		session_unset();
		session_destroy();
		go(U('Login/index'));
	}
}
 ?>